#ifndef LEXER_H__
#define LEXER_H__

#include "seg.h"
#include "kw.h"
#include "token.h"

#define TOKEN_MAX_SIZE 64

enum {
	KEY_NONE = 0,
	KEY_NEWLINE,
	KEY_COMMA,
	KEY_BACKSPACE1,
	KEY_BACKSPACE2,
	KEY_TABLE,
};

#define TRIGGER_SET           "\n;\b\x7f\t"

#define TRIGGER_NEWLINE       '\n'
#define TRIGGER_COMMA         ';'
#define TRIGGER_BACKSPACE1    '\b'
#define TRIGGER_BACKSPACE2    '\x7f'
#define TRIGGER_TABLE         '\t'


#define LEXER_AUTOFILL   32

struct lexer {
	const char *buf;
	int buf_size;
	struct token token;
  struct token backup;
	struct seg_list eol;
  struct seg_list args;

	struct seg_list free_kw;
	struct kw *kw_pool[SEG_LIMIT];
	char autofill[LEXER_AUTOFILL];
};

enum {
	LEXER_NONE,
	LEXER_SIB,
	LEXER_SON,
	LEXER_OWN,
};

void lexer_set_root(struct kw *root);

int print_token(seg_t seg, const void *_u);

static inline const char *lexer_get_autofill(struct lexer *lex)
{
	return lex->autofill;
}


static inline void lexer_reset_autofill(struct lexer *lex)
{
	lex->autofill[0] = 0;
}
	
seg_t lexer_prepare(const char *buf, int buf_size);

void init_lexer(struct lexer *lex, const char *buf, seg_t cmd);
void show_lexer (struct lexer *lex, int ret);

int lexer_execute(void *lex);
int lexer_help(struct lexer *lex);




#endif
